🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / takserver / src / commonTest / kotlin / org / meshtastic / core / takserver / TakV2CompressorBoundaryTest.kt
Displaying Raw • Download
core/takserver/src/commonTest/kotlin/org/meshtastic/core/takserver/TakV2CompressorBoundaryTest.kt 65a1f5ce4d0e4b8eafcd0bbfccafd41dc6ee888a (65a1f5ce) Text, 2.28 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.takserver
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals
Tff7b72import T7ee787kotlin.test.assertTrue
T8b949e/**
* Tests for [TakV2Compressor] size boundary validation (T077).
*
* Verifies that:
* - MAX_DECOMPRESSED_SIZE is a reasonable constant (4096 bytes)
* - Dictionary IDs are correctly defined
* - The uncompressed marker (0xFF) is correct
*/
Tff7b72class T56d364TakV2CompressorBoundaryTest Tb4b4b4{
Tf0883e@Test
Tff7b72fun Td2a8ff`MAX_DECOMPRESSED_SIZE is 4096 bytes`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(T79c0ff4T79c0ff0T79c0ff9T79c0ff6Tb4b4b4, Te6edf3TakV2CompressorTb4b4b4.Te6edf3MAX_DECOMPRESSED_SIZETb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`MAX_DECOMPRESSED_SIZE is greater than mesh MTU`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// MAX_TAK_WIRE_PAYLOAD_BYTES = 225. Decompressed size must be larger than the
T8b949e// compressed wire payload to be useful. Also ensures there's a reasonable
T8b949e// amplification cap to prevent decompression bombs.
Te6edf3assertTrueTb4b4b4(Te6edf3TakV2CompressorTb4b4b4.Te6edf3MAX_DECOMPRESSED_SIZE Tff7b72> Te6edf3MAX_TAK_WIRE_PAYLOAD_BYTESTb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`MAX_DECOMPRESSED_SIZE is bounded to prevent memory exhaustion`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// A decompression bomb could expand a small payload into megabytes. The limit
T8b949e// must be small enough to prevent OOM in constrained Android environments.
Te6edf3assertTrueTb4b4b4(Te6edf3TakV2CompressorTb4b4b4.Te6edf3MAX_DECOMPRESSED_SIZE Tff7b72<Tff7b72= T79c0ff6T79c0ff5T79c0ff5T79c0ff3T79c0ff6Tb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`dictionary IDs are correctly assigned`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(T79c0ff0Tb4b4b4, Te6edf3TakV2CompressorTb4b4b4.Te6edf3DICT_ID_NON_AIRCRAFTTb4b4b4)
Te6edf3assertEqualsTb4b4b4(T79c0ff1Tb4b4b4, Te6edf3TakV2CompressorTb4b4b4.Te6edf3DICT_ID_AIRCRAFTTb4b4b4)
Tb4b4b4}
Tf0883e@Test
Tff7b72fun Td2a8ff`uncompressed marker is 0xFF`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(T79c0ff0Te6edf3xFFTb4b4b4, Te6edf3TakV2CompressorTb4b4b4.Te6edf3DICT_ID_UNCOMPRESSEDTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s